package com.qianyitian.hope2.analyzer.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class InfoController {
    @RequestMapping(value = "/myip", method = RequestMethod.GET)
    @ResponseBody
    public String myip(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        map.put("x-forwarded-for", request.getHeader("x-forwarded-for"));
        map.put("Proxy-Client-IP", request.getHeader("Proxy-Client-IP"));
        map.put("WL-Proxy-Client-IP", request.getHeader("WL-Proxy-Client-IP"));
        map.put("request.getRemoteAddr", request.getRemoteAddr());
        map.put("request.getRemoteHost()", request.getRemoteHost());

        String content = JSON.toJSONString(map, true);
        return content;
    }
}
